import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

public class QQInputForm {
    private JFrame frame;
    private JTextField qqField;

    public QQInputForm() {
        initialize();
    }

    private void initialize() {
        frame = new JFrame("QQ号登录");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(300, 150);
        frame.setLayout(new GridLayout(2, 1));

        JLabel label = new JLabel("请输入QQ号:", SwingConstants.CENTER);
        qqField = new JTextField(10);

        // 限制只能输入数字
        qqField.addKeyListener(new KeyAdapter() {
            @Override
            public void keyTyped(KeyEvent e) {
                char ch = e.getKeyChar();
                if (!Character.isDigit(ch)) {
                    e.consume(); // 非数字字符不允许输入
                }
            }
        });

        JPanel panel = new JPanel();
        panel.add(label);
        frame.add(panel);

        JPanel fieldPanel = new JPanel();
        fieldPanel.add(qqField);
        frame.add(fieldPanel);

        frame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(QQInputForm::new);
    }
}
